﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using ExtAspNet;

namespace HY.WEB.OA
{
    public partial class _charge_approl : PageBase
    {
        public string whe = "", stype = "";
        public string us, nm, tab = "review_charge";
        protected void Page_Load(object sender, EventArgs e)
        {  
            us=Session["ID"].ToString();
            nm = Session["user"].ToString();
            if (!IsPostBack)
            {
                btnSearch.OnClientClick = Window1.GetShowReference("../function/search.aspx?tab="+tab+"", "高级搜索");
                fill();
                BindGrid();
            }

        }

        private void fill()
        {
            DataTable d = BLL.BLLfun.get_search(tab);
            ddlfiled.Items.Clear();
            for (int i = 0; i < d.Rows.Count; i++)
            {
                ddlfiled.Items.Add(new ExtAspNet.ListItem(d.Rows[i][1].ToString(), d.Rows[i][0].ToString()));
            }
            ddlfiled.DataBind();

            DataTable e = BLL.BLLfun.get_where();
            ddlwhere.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlwhere.Items.Add(new ExtAspNet.ListItem(e.Rows[i][0].ToString(), e.Rows[i][1].ToString()));
            }
             ddlwhere.DataBind();   ddlwhere.SelectedIndex = ddlwhere.Items.IndexOf(ddlwhere.Items.FindByValue("="));
        }

        public  string getnm(string nmid)
        {
            BLL.HR.sys_user u = new BLL.HR.sys_user();
            return BLL.BLLfun.getname(nmid);
        }


        private void BindGrid()
        {
            DataTable  table2 = BLL.oa.charge_sub.getleaveapp_n(nm,whe); //all

       
           // DataTable  table2=BLL.Bllbase.get_table(tab,whe);
           // table2 = BLL.oa.leave_sub.getleaveapp_all(nm); //all
            Grid2.DataSource = table2;
            Grid2.DataBind();         
       
        }


        //获取审批状戊
        public string getstatus(string nmid)
        {
            return BLL.oa.charge_sub.getstatus(nmid);
        }

        protected void Grid2_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Grid2.PageIndex = e.NewPageIndex;
        }

        protected void Grid2_Sort(object sender, ExtAspNet.GridSortEventArgs e)
        {
           // DataTable table = BLL.Bllbase.get_table(tab, whe);
            //DataTable table = BLL.oa.ad.get_list(stype);

            DataTable table = BLL.oa.charge_sub.getleaveapp_n(nm, whe); //all

            DataView view1 = table.DefaultView;
            view1.Sort = String.Format("{0} {1}", e.SortField, e.SortDirection);

            Grid2.DataSource = view1;
            Grid2.DataBind();
        }   

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ttbSearchMessage_Trigger2Click(object sender, EventArgs e)
        {
            txt.ShowTrigger1 = true;
            string ddlf = ddlfiled.SelectedValue;
            string ddlw = ddlwhere.SelectedValue;
           string key = txt.Text.Trim();
            if (ddlw.Equals("="))
                whe = " and b." + ddlf + " like  '%" + key + "%'";
            else
            {
                if (ddlf == "sid" || ddlf == "编号")
                    whe = "and b." + ddlf + " " + ddlw + " " + key + "";
                else
                    whe = "and b." + ddlf + " " + ddlw + " '" + key + "'";

            }
            if (key == "") whe = "";

            BindGrid();
        }

        /// <summary>
        /// 清除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ttbSearchMessage_Trigger1Click(object sender, EventArgs e)
        {
            txt.Text = String.Empty;
            txt.ShowTrigger1 = false;
            BindGrid();
        }


        protected void btnn_Click(object sender, EventArgs e)
        {

            DataTable table2;

            table2 = BLL.oa.charge_sub.getleaveapp_n(nm,whe); //all

            Grid2.DataSource = table2;
            Grid2.DataBind();         
       

            //StringBuilder sb = new StringBuilder();
            //foreach (int row in Grid2.SelectedRowIndexArray)
            //{
            //    sb.Append(Grid2.DataKeys[row][0].ToString());
            //    sb.Append(",");
            //}

            ////Alert.ShowInTop("你选择了删除项：" + sb.ToString().TrimEnd(','));

            //HY.BLL.oa.leave_sub.dellist_eqau(sb.ToString().TrimEnd(','));          
            //BindGrid();

        }

        protected void btny_Click(object sender, EventArgs e)
        {

            DataTable table2;

            table2 = BLL.oa.charge_sub.getleaveapp_y(nm,whe); //all

            Grid2.DataSource = table2;
            Grid2.DataBind();

        }

        protected void btnall_Click(object sender, EventArgs e)
        {

            DataTable table2;

            table2 = BLL.oa.charge_sub.getleaveapp_all(nm,whe); //all

            Grid2.DataSource = table2;
            Grid2.DataBind();

        }


        protected void Grid2_RowCommand(object sender, ExtAspNet.GridCommandEventArgs e)
        {
            if (e.CommandName == "sub") //修改 
            {
                string DD = Grid2.DataKeys[e.RowIndex][0].ToString();

                     string bh = Grid2.DataKeys[e.RowIndex][1].ToString();
                //已审批完成不能修改
                     if (BLL.oa.charge_sub.check_approl(bh))
                     {
                         Alert.Show("已审批完成单据,不能修改。");
                         return;
                     }

               // BLL.oa.review_leave S = new BLL.oa.review_leave();
            
                DataTable dt1 =BLL.Bllbase.get_table(tab,"sid="+DD+"");           
                hidsid.Text = dt1.Rows[0]["sid"].ToString().Trim();
                lblbh.Text = dt1.Rows[0]["gbh"].ToString().Trim();
                lblnm.Text = dt1.Rows[0]["item"].ToString().Trim();

             }
            else if (e.CommandName == "Del")//删除 
            {

            } 

        }

 
        protected void Window1_Close(object sender, EventArgs e)
        {
            // Alert.ShowInTop("弹出窗口关闭了！");
           string key = txt.Text.Trim();
          //  stype = hidstype.Text;
            try
            {
                if (key == "") whe = BLL.pub.pubwhere.get_where_sql(us,tab);
                BindGrid();

            }
            catch (Exception ex)
            {
              //  Alert.Show("查询条件错误");
            }
            finally
            {
                whe = "";
            }
        }

        protected void btsave_Click(object sender, EventArgs e)
        {
            string user=nm; //审批人

            string bh=lblbh.Text; //编号

            if (bh == "")
            {
                Alert.Show("请选择要审批的单号");
                return;
            }

            string val = "";

            if (rbtnFirst.Checked)
                val ="同意";

            if (rbtnSecond.Checked)
                val = "不同意";
            string memo = txtmemo.Text;


            BLL.oa.charge_sub.up_data(bh, nm, val, memo);     

            hidsid.Text = "";
            BindGrid();
            lblbh.Text = "";
            lblnm.Text = "";
        }

   


    
    }
}